<?php
namespace common\models;

/**
 * 管理模型基础类
 * Class BaseModel
 * @package common\models
 */
abstract class BaseModels extends \yii\db\ActiveRecord
{

    /**
     * findOrCreate
     * @param mixed $condition
     * @return static
     */
    public static function findOrCreate($condition)
    {
        if(empty($model = self::findOne($condition))){
            $model = new static();
            $model->loadDefaultValues();
            if(is_array($condition)){
                $model->load($condition,'');
            }
        }
        return $model;
    }

    /**
     * getFirstErrorMsg
     * @param string $defaultMsg
     * @return string|null
     */
    public function getFirstErrorMsg($defaultMsg='操作失败')
    {
        return getModelErrorMsg($this,$defaultMsg);
    }
}